import store from 'store'
import {get} from './request'

const KEY = 'pcg_admin_address_list'
const getAds = ()=>{
	return store.get(KEY) || {}
}
const setAds = (data)=>{
	store.set(KEY,data)
}

export const getAddress=()=>{
	let {version='',models=[]} = getAds() || {}
	let params = {
		showMsg:false,
		version:version,
	}
	return new Promise((resolve,reject)=>{
		get('/api/order/addressRepository',params)
		.then(({errorCode,result})=>{
			if(errorCode===0&&result.models.length){
				setAds({
						models:result.models,
						version:result.version
					})
				resolve(result.models)
			}else{
				resolve(models)
			}
		})
	})
}